﻿<r:RibbonWindow x:Class="MDCAdminTool.MainWindow" 
    xmlns   ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:r ="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
    xmlns:me="clr-namespace:MDCAdminTool.Commands"        
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:Controls="clr-namespace:MDCAdminTool.Controls" xmlns:Logger="clr-namespace:MDCAdminTool.Logger" Title   = "Microsoft Distributed Cache (MDC) Admin Tool"  
    Height  = "600" 
    Width   = "900" mc:Ignorable="d" 
    Background="White" 
    WindowState="Maximized" 
    Loaded="RibbonWindow_Loaded" SourceInitialized="RibbonWindow_SourceInitialized">

    <r:RibbonWindow.Resources>
        <Storyboard x:Key="SpinStoryboard">
            <DoubleAnimationUsingKeyFrames 
               BeginTime="00:00:00" 
               RepeatBehavior="Forever"
               Storyboard.TargetName="Logo" 
               Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)">
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="360"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </r:RibbonWindow.Resources>

    <r:RibbonWindow.Triggers>
        <EventTrigger  RoutedEvent="Controls:AsyncProgressBar.StartProgress">
            <BeginStoryboard Name="beginSpinStoryboard" Storyboard="{StaticResource SpinStoryboard}" />
        </EventTrigger>
        <EventTrigger RoutedEvent="Controls:AsyncProgressBar.StopProgress">
            <StopStoryboard BeginStoryboardName="beginSpinStoryboard" />
        </EventTrigger>
    </r:RibbonWindow.Triggers>

    <Window.CommandBindings>

        <!-- Misc -->
        <!-- Cache Cluster -->
        <me:StartCacheCluster/>
        <me:StopCacheCluster />
        <me:RestartCacheCluster/>
        <me:RenameCacheCluster/>
        <me:SaveConfigCacheCluster />
        <me:AddCacheHost     />
        <me:GetCacheClusterHealth/>
        

        <me:ConfigCacheCluster />
        <me:LoadConfigCacheCluster />
        <me:ExportConfigCacheCluster />
        <me:ImportConfigCacheCluster />
        <me:ManageClusterSecurity />
        <!--<CommandBinding 
        Command="{StaticResource SystemRequirementsCacheCluster}" 
        CanExecute="CommandBinding_CanExecute"
        Executed="CommandBinding_Executed" />-->

        <!-- Cache Host -->
        <me:StartCacheHost      />
        <me:StopCacheHost       />
        <me:StatisticsCacheHost />
        <me:ConfigCacheHost     />
        <me:SaveCacheHost       />
        <me:ReloadCacheHost     />

        <me:RemoveCacheHost/>
        <me:StartPowerShell/>


        <!-- Cache Name -->
        <me:AddCacheName        />
        <me:RemoveCacheName     />
        <me:StatisticsCacheName />
        <me:ConfigCacheName     />
        <me:SaveCacheName       />
        <me:AddRegionCacheName  />
        <me:RemoveRegionCacheName />
        <me:AddDataCacheItem    />
        <me:ShowCacheMetrics/>

        <!-- Data Cache -->
        <!--<me:SearchDataCache />-->
        
        <!-- UI -->

        <!-- Reports -->
        <me:ClusterSize />
        <me:CacheNameSizesByHost />
        <me:CacheNameStats />
        <me:CacheHostStats />

    </Window.CommandBindings>
    <Grid>
        <DockPanel>

            <r:Ribbon Name="ribbon"  DockPanel.Dock="Top">

                <r:Ribbon.Resources>
                    <r:RibbonGroupSizeDefinitionCollection x:Key="RibbonLayout">
                        <r:RibbonGroupSizeDefinition>
                            <!-- Control sizes: L,L,L -->
                            <r:RibbonControlSizeDefinition ImageSize="Large" IsLabelVisible="True"/>
                            <r:RibbonControlSizeDefinition ImageSize="Large" IsLabelVisible="True"/>
                            <r:RibbonControlSizeDefinition ImageSize="Large" IsLabelVisible="True"/>
                        </r:RibbonGroupSizeDefinition>
                        <r:RibbonGroupSizeDefinition>
                            <!-- Control sizes: L,M,M -->
                            <r:RibbonControlSizeDefinition ImageSize="Large" IsLabelVisible="True"/>
                            <r:RibbonControlSizeDefinition ImageSize="Small" IsLabelVisible="True"/>
                            <r:RibbonControlSizeDefinition ImageSize="Small" IsLabelVisible="True"/>
                        </r:RibbonGroupSizeDefinition>
                        <r:RibbonGroupSizeDefinition>
                            <!-- Control sizes: L,S,S -->
                            <r:RibbonControlSizeDefinition ImageSize="Large" IsLabelVisible="True"/>
                            <r:RibbonControlSizeDefinition ImageSize="Small" IsLabelVisible="False"/>
                            <r:RibbonControlSizeDefinition ImageSize="Small" IsLabelVisible="False"/>
                        </r:RibbonGroupSizeDefinition>
                        <!-- Collapsed -->
                        <r:RibbonGroupSizeDefinition IsCollapsed="True" />
                    </r:RibbonGroupSizeDefinitionCollection>
                </r:Ribbon.Resources>

                <r:Ribbon.ApplicationMenu>
                    <r:RibbonApplicationMenu>
                        <r:RibbonApplicationMenu.Command>
                            <r:RibbonCommand                             
                            LabelTitle="Application Button"
                            LabelDescription="Close the application."
                            SmallImageSource="Resources/E4DLogo60x60.png"
                            LargeImageSource="Resources/E4DLogo60x60.png"
                            ToolTipTitle="MDC Admin Tool"
                            ToolTipDescription="Todo" />
                        </r:RibbonApplicationMenu.Command>
                        <!--<r:RibbonApplicationMenuItem>
                  <r:RibbonApplicationMenuItem.Command>
                     <r:RibbonCommand 
                                LabelTitle="_Close" 
                                LabelDescription="Close the Application"
                                Executed="OnCloseApplication" />
                  </r:RibbonApplicationMenuItem.Command>
               </r:RibbonApplicationMenuItem>-->
                    </r:RibbonApplicationMenu>
                </r:Ribbon.ApplicationMenu>
                <!-- Cache Cluster Tab -->
                <r:RibbonTab Label="Cluster" Name="rtCluster">
                    <r:RibbonGroup GroupSizeDefinitions="{StaticResource RibbonLayout}">
                        <r:RibbonGroup.Command>
                            <r:RibbonCommand LabelTitle="Cluster Command" />
                        </r:RibbonGroup.Command>
                        <!--<r:RibbonButton Command="{StaticResource SystemRequirementsCacheCluster }"  CommandParameter="{Binding}"/>-->
                        <r:RibbonButton Command="{StaticResource StartCacheCluster }"  CommandParameter="{Binding}"/>
                        <r:RibbonButton Command="{StaticResource StopCacheCluster}"    CommandParameter="{Binding}"/>
                        <r:RibbonButton Command="{StaticResource RestartCacheCluster}" CommandParameter="{Binding}"/>
                        <r:RibbonButton Command="{StaticResource RenameCacheCluster}"  CommandParameter="{Binding}"/>
                        <r:RibbonButton Command="{StaticResource AddCacheHost}"        CommandParameter="{Binding}"/>
                        <r:RibbonButton Command="{StaticResource AddCacheName}"          CommandParameter="{Binding}"/>
                        <r:RibbonButton Command="{StaticResource ConfigCacheCluster}"  CommandParameter="{Binding}"/>
                        <r:RibbonButton Command="{StaticResource ClusterSize}" CommandParameter="{Binding}" />
                        <r:RibbonButton Command="{StaticResource GetCacheClusterHealth}" CommandParameter="{Binding}" />
                        <r:RibbonButton Command="{StaticResource ManageClusterSecurity}" CommandParameter="{Binding}" />
                    </r:RibbonGroup>
                </r:RibbonTab>

                <!-- Cache Host Tab -->
                <r:RibbonTab Label="Host" Name="rtHost">
                    <r:RibbonGroup GroupSizeDefinitions="{StaticResource RibbonLayout}">
                        <r:RibbonGroup.Command>
                            <r:RibbonCommand LabelTitle="Cache Host Command" />
                        </r:RibbonGroup.Command>
                        <r:RibbonButton Command="{StaticResource StartCacheHost}"      CommandParameter="{Binding}"/>
                        <r:RibbonButton Command="{StaticResource StopCacheHost}"       CommandParameter="{Binding}"/>
                        <r:RibbonButton Command="{StaticResource RestartCacheHost}"       CommandParameter="{Binding}"/>
                        <!--<r:RibbonButton Command="{StaticResource StatisticsCacheHost}" CommandParameter="{Binding}"/>-->
                        <r:RibbonButton Command="{StaticResource ConfigCacheHost}"     CommandParameter="{Binding}"/>
                        <r:RibbonButton Command="{StaticResource CacheHostStats}" CommandParameter="{Binding}" />
                        <r:RibbonButton Command="{StaticResource CacheNameSizesByHost}" CommandParameter="{Binding}"/>
                        <!-- host commands -->

                        <r:RibbonButton Command="{StaticResource RemoveCacheHost}" CommandParameter="{Binding}"/>
                        <r:RibbonButton Command="{StaticResource StartPowerShell }" CommandParameter="{Binding}"/>
                        <r:RibbonButton Command="{StaticResource ReloadCacheHost}"       CommandParameter="{Binding}"/>

                    </r:RibbonGroup>
                </r:RibbonTab>

                <!-- Cache Name Tab -->
                <r:RibbonTab Label="Cache" Name="rtCache">

                    <r:RibbonGroup GroupSizeDefinitions="{StaticResource RibbonLayout}">
                        <r:RibbonGroup.Command>
                            <r:RibbonCommand LabelTitle="Cache Commands" />
                        </r:RibbonGroup.Command>
                        <r:RibbonButton Command="{StaticResource RemoveCacheName}" CommandParameter="{Binding}"/>
                        <r:RibbonButton Command="{StaticResource AddRegionCacheName}" CommandParameter="{Binding}"/>
                        <r:RibbonButton Command="{StaticResource AddDataCacheItemCommand}" CommandParameter="{Binding}"/>

                        <!--<r:RibbonButton Command="{StaticResource StatisticsCacheName}" CommandParameter="{Binding}"/>-->
                        <r:RibbonButton Command="{StaticResource ConfigCacheName}" CommandParameter="{Binding}"/>
                        <r:RibbonButton Command="{StaticResource CacheNameStats}" CommandParameter="{Binding}"/>

                    </r:RibbonGroup>
                </r:RibbonTab>


            </r:Ribbon>

            <StatusBar DockPanel.Dock="Bottom">
                <StatusBarItem Content="Microsoft Distributed Cache (MDC) Admin Tool" />
                <StatusBarItem Margin="0,2,15,2" HorizontalContentAlignment="Stretch">
                    <Controls:AsyncProgressBar 
                  x:Name="powerShellProgressBar"                 
                  HorizontalAlignment="Stretch" Height="10" Margin="25,0,0,0" >
                    </Controls:AsyncProgressBar>
                </StatusBarItem>
            </StatusBar>

            <Border BorderBrush="#BFDBFF" BorderThickness="5" Background="#F2F5FB">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="0.7*"/>
                        <RowDefinition Height="0.3*"/>
                    </Grid.RowDefinitions>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="0.25*"/>
                        <ColumnDefinition Width="0.75*"/>
                    </Grid.ColumnDefinitions>

                    <Border x:Name="TreeBorder_" Grid.Column= "0" Grid.Row= "0" Grid.RowSpan="2"  BorderBrush="#69A1BF" BorderThickness="1" Margin="0" >
                        <TreeView 
                     Name = "ClustersTreeView" 
                     ItemsSource="{Binding}"  
                     SelectedItemChanged = "ClustersTreeView_SelectedItemChanged"
                     MouseDoubleClick="ClustersTreeView_MouseDoubleClick"      
                     BorderBrush = "#00828790" >
                        </TreeView>
                    </Border>

                    <GridSplitter HorizontalAlignment="Left" Width="4" Grid.Column="1" Grid.RowSpan="2" Background="#BFDBFF"/>

                    <Border x:Name="TabBorder_" Grid.Column="1" Grid.Row="0" BorderBrush="#69A1BF" BorderThickness="1,1,1,0" Margin="2,0,0,0">
                        <TabControl Name="tabControl" Margin="2" Grid.RowSpan="1">
                            <TabControl.CommandBindings>
                                <me:TabClose/>
                            </TabControl.CommandBindings>
                        </TabControl>
                    </Border>

                    <GridSplitter Grid.Column="1" Height="5" Margin="2,0,1,0" HorizontalAlignment="Stretch" Grid.Row="1" VerticalAlignment="Top" Background="#BFDBFF" Style="{DynamicResource GridSplitterStyle}" />
                    <Border x:Name="PSBorder_" Grid.Column="1" Grid.Row="1" BorderBrush="#69A1BF" BorderThickness="1,0,1,1" Margin="2,1,0,0">
                        <GroupBox  Margin="8" Padding="8">

                            <GroupBox.Header>
                                <StackPanel Orientation="Horizontal">
                                    <Image Name="img" Source="Resources\cmd.ico" Height="16" Width="16" />
                                    <TextBlock Text="PowerShell Output" Margin="5,0,0,0"/>
                                </StackPanel>
                            </GroupBox.Header>

                            <Logger:ListBoxLogger x:Name="lbOutput">
                                <Logger:ListBoxLogger.ContextMenu>
                                    <ContextMenu>
                                        <MenuItem Header ="Delete PowerShell Result" Command="{StaticResource CollectionClear}" Icon="{StaticResource Delete16}"/>
                                        <MenuItem Header="Copy Command" Command="{StaticResource CopyCommand}" CommandParameter="{Binding ElementName=lbOutput}" Icon="{StaticResource Copy}" />
                                    </ContextMenu>
                                </Logger:ListBoxLogger.ContextMenu>
                                <Logger:ListBoxLogger.CommandBindings>
                                    <me:CollectionClear     />
                                    <me:CopyCommand />
                                </Logger:ListBoxLogger.CommandBindings>
                            </Logger:ListBoxLogger>
                        </GroupBox>
                    </Border>
                </Grid>
            </Border>

        </DockPanel>
        
        <Image Name="Logo"
         Margin="0,55,25,0"
         HorizontalAlignment="Right" VerticalAlignment="Top" Width="70" Height="70" 
         Source="/MDCAdminTool;Component/Resources/experts4dlogo_new_Small.png"
         RenderTransformOrigin="0.5,0.5">
            <Image.RenderTransform>
                <TransformGroup>
                    <RotateTransform/>
                </TransformGroup>
            </Image.RenderTransform>
        </Image>

    </Grid>
</r:RibbonWindow>
